﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.IDAL;
using KPIS.GERP.GFMS.DALFactory;

// test only
using KPIS.GERP.GFMS.DAL;

namespace KPIS.GERP.GFMS.BLL
{
    public class B_FIM_Petitions : IBLL_FIM_Petitions
    {
        Common common = new Common();
        private static readonly IDAL_FIM_Petitions dal = DataAccess.Create_FIM_Petitions();
        //D_FIM_MAS_Receives r = new D_FIM_MAS_Receives();

        public B_FIM_Petitions()
        {

        }

        public IList<M_FIM_Petitions> GetFull(string bgm_source_seq, string bgm_year)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            return dal.GetFull(nbgm_source_seq, nbgm_year);
        }

        public IList<M_FIM_Petitions> GetList(string bgm_source_seq, string bgm_year, string filter)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            return dal.GetList(nbgm_source_seq, nbgm_year, filter);
        }

        public IList<M_FIM_Petitions> GetDirectPaymentList(string bgm_source_seq
            , string bgm_year, string petition_seq)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            Nullable<int> npetition_seq = common.ConvertNullInt(petition_seq);
            return dal.GetDirectPaymentList(nbgm_source_seq, nbgm_year, npetition_seq);
        }

        public IList<M_FIM_Petitions> GetApprovedList(string bgm_source_seq, string bgm_year, string filter)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            return dal.GetApprovedList(nbgm_source_seq, nbgm_year, filter);
        }

        //public string SelectRecentInsertedRoleSeq()
        //{
        //    return dal.SelectRecentInsertedRoleSeq();
        //}

        public M_FIM_Petitions GetInfo(string seq)
        {
            int nSeq;
 
            if (seq == null)
                return null;

            if (common.IsNumeric(seq))
            {
                nSeq = int.Parse(seq);
                return dal.GetInfo(nSeq);
            }
            else
            {
                return null;
            }
        }

        public string Insert(M_FIM_Petitions info)
        {
            try
            {
                return dal.Insert(info);
            }
            catch
            {
                throw;
            }
        }

        public void Update(M_FIM_Petitions info)
        {
            try
            {
                dal.Update(info);
            }
            catch
            {
                throw;
            }
        }

        public void Delete(M_FIM_Petitions info)
        {
            try
            {
                dal.Delete(info);
            }
            catch
            {
                throw;
            }
        }

        public void UpdateGlTranSeq(M_FIM_Petitions info)
        {
            try
            {
                dal.UpdateGlTranSeq(info);
            }
            catch
            {
                throw;
            }
        }

        public void UpdatePetitionNo(M_FIM_Petitions info)
        {
            try
            {
                dal.UpdatePetitionNo(info);
            }
            catch
            {
                throw;
            }
        }

        public void ChangeStatus(M_FIM_Petitions info)
        {
            try
            {
                dal.ChangeStatus(info);
            }
            catch
            {
                throw;
            }
        }
    }
}
